import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Test{
    public static void main(String[] args) {
        List<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        //foreach遍历
        for(int x : list){
            System.out.println(x);
        }
        //迭代器
        ListIterator<Integer> it = list.listIterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();
        //倒序
        ListIterator<Integer> it2 = list.listIterator(list.size());
        while(it2.hasPrevious()){
            System.out.print(it2.previous() + " ");
        }
        System.out.println();
    }
}

